package com.ml.shs.service;

import com.ml.shs.entity.Discuss;
import com.ml.shs.repository.DiscussRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpSession;
import java.util.Date;
import java.util.List;


@Service
public class DiscussService {

    @Autowired
    DiscussRepository discussRepository;

    @Autowired
    HttpSession session;

    public List<Discuss> getList(){
        return  discussRepository.findAll();
    }

    public void save(Discuss discuss){
        discuss.setCreateTime(new Date());
        Object userId  = session.getAttribute("userId");
        discuss.setCreaterId(userId.toString());
        Object userName  = session.getAttribute("userName");
        discuss.setCreaterName(userName.toString());
        discussRepository.save(discuss);
    }
}
